#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/6/17 23:00
# @Author : cjw
from typing import Union


class Calculator:
    """计算器"""

    def add(self, num1: Union[int, float], num2: Union[int, float]) -> Union[int, float]:
        """
        加法，四舍五入保留两位小数
        :param num1:
        :param num2:
        :return:
        """
        if not isinstance(num1, (int, float)):
            raise TypeError(f'类型错误，只能是数字类型(int, float)：{num1}')
        if not isinstance(num2, (int, float)):
            raise TypeError(f'类型错误，只能是数字类型(int, float)：{num2}')
        result = num1 + num2
        return round(result, 2)

    def div(self, num1: Union[int, float], num2: Union[int, float]) -> Union[int, float]:
        """
        除法
        :param num1:被除数
        :param num2:除数
        :return:
        """
        if not isinstance(num1, (int, float)):
            raise TypeError(f'类型错误，只能是数字类型(int, float)：{num1}')
        if not isinstance(num2, (int, float)):
            raise TypeError(f'类型错误，只能是数字类型(int, float)：{num2}')
        try:
            result = num1 / num2
        except ZeroDivisionError as ex:
            raise ex
        return round(result, 2)


if __name__ == '__main__':
    calc = Calculator()
    # print(calc.add(1, 1))
    print(calc.div(999999999, 44444))
